package com.zdb.util;

import cn.hutool.json.JSONUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class RenderUtil {
    private static final Logger log = LoggerFactory.getLogger(RenderUtil.class);

    public static final String renderString(HttpServletResponse response, String string, Integer  code) {
        try {
            response.setStatus(code);
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(string);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static final String renderString(HttpServletResponse response,Integer  code,Object  object) {

        try {
            response.setStatus(code);
            response.setContentType("application/json");
            response.setCharacterEncoding("utf-8");
            response.getWriter().print(JSONUtil.toJsonStr(object));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
